package xfsale.service.impl.j2ee;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import org.apache.log4j.Logger;

import xfsale.util.StringUtil;

@SuppressWarnings("unused")
public final class PubSerial {

	private String distributorCode;		//销售商代码
	private String regionCode;			//地区编码
	private String branchCode;			//网点编码
    private String netCode;             //销售网点编码
	private String tradeDate;			//交易日期
	private String tradeTime;			//交易时间
	private String orderSerialNo;		//委托流水
	private String appSerialNo;			//申请流水
	private String ackSerialNo;			//确认流水
	private String logSerialNo;			//日志流水
	private String moneySerialNo;		//资金流水
	private String remitSerialNo;		//汇款凭证流水
	private String transferSerialNo;	//资金转帐流水
	private Connection conn;			//数据库连接
	private Logger logger = Logger.getLogger(PubAcct.class);	//日志

	public PubSerial(Connection conn) {
		this.conn = conn;
	}

	public void setDdistributorCode(String distributorCode) {
		this.distributorCode = distributorCode;
	}

	public void setRegionCode(String regionCode) {
		this.regionCode = regionCode;
	}

	public void setBranchCode(String branchCode) {
		this.branchCode = branchCode;
	}

	public void setNetCode(String netCode) {
		this.netCode = netCode;
	}

	public void setTradeDate(String tradeDate) {
		this.tradeDate = tradeDate;
	}

	public void setTradeTime(String tradeTime) {
		this.tradeTime = tradeTime;
	}

	public String getOrderSerialNo() {
		return orderSerialNo;
	}

	public String getAppSerialNo() {
		return appSerialNo;
	}

	public String getAckSerialNo() {
		return ackSerialNo;
	}

	public String getLogSerialNo() {
		return logSerialNo;
	}

	public String getMoneySerialNo() {
		return moneySerialNo;
	}

	public String getRemitSerialNo() {
		return remitSerialNo;
	}

	public String getTransferSerialNo() {
		return transferSerialNo;
	}

	public void genOrderSerial() throws Exception {
		Statement stmt = conn.createStatement();
		try {
			logger.info("生成委托流水...");
			ResultSet rs = stmt.executeQuery("select SEQ_ORDERSERIAL.nextval from dual");
			rs.next();
			orderSerialNo = rs.getString(1);
			orderSerialNo = tradeDate + StringUtil.lpadz(orderSerialNo, 8);
			logger.debug("委托流水: " + orderSerialNo);
		} catch (Exception e) {
			logger.error("生产委托流水出错. " + e);
			throw e;
		} finally {
			stmt.close();
		}
	}

	public void genAppSerial() throws Exception {
		Statement stmt = conn.createStatement();
		try {
			logger.info("生成申请流水...");
			ResultSet rs = stmt.executeQuery("select SEQ_APPSERIAL.nextval from dual");
			rs.next();
			appSerialNo = rs.getString(1);
			appSerialNo = tradeDate + StringUtil.lpadz(appSerialNo, 8);
			logger.debug("申请流水: " + appSerialNo);
		} catch (Exception e) {
			logger.error("生产申请流水出错. " + e);
			throw e;
		} finally {
			stmt.close();
		}
	}

	public void genAckSerial() throws Exception {
		Statement stmt = conn.createStatement();
		try {
			logger.info("生成确认流水...");
			ResultSet rs = stmt.executeQuery("select SEQ_ACKSERIAL.nextval from dual");
			rs.next();
			ackSerialNo = rs.getString(1);
			ackSerialNo = tradeDate + StringUtil.lpadz(ackSerialNo, 8);
			logger.debug("确认流水:" + ackSerialNo);
		} catch (Exception e) {
			logger.error("生产确认流水出错. " + e);
			throw e;
		} finally {
			stmt.close();
		}
	}

	public void genLogSerial() throws Exception {
		Statement stmt = conn.createStatement();
		try {
			logger.info("生成日志流水...");
			ResultSet rs = stmt.executeQuery("select SEQ_OPLOGSERIAL.nextval from dual");
			rs.next();
			logSerialNo = rs.getString(1);
			logSerialNo = tradeDate + StringUtil.lpadz(logSerialNo, 8);
			logger.debug("日志流水: " + logSerialNo);
		} catch (Exception e) {
			logger.error("生产日志流水出错. " + e);
			throw e;
		} finally {
			stmt.close();
		}
	}

	public void genMoneySerial() throws Exception {
	}

	public void genRemitSerial() throws Exception {
	}

	public void genTransferSerial() throws Exception {
	}

}
